//
//  TbGoodsListModel.m
//  quxiangtao
//
//  Created by xbmios on 2018/9/26.
//  Copyright © 2018年 shanhaijin. All rights reserved.
//

#import "TbGoodsListModel.h"

@implementation TbGoodsListModel

+ (void)goodsListWithUrl:(NSString *)url andPage:(NSInteger)page withClassID:(NSString *)classID successBlock:(HttpRequestSuccess)succcess failBlock:(HttpRequestFailed)fail {

    NSString *par = [NSString stringWithFormat:@"{\"device_value\" : \"%@\", \"device_type\" : \"%@\", \"classid\" : \"%@\", \"device_encrypt\" : \"%@\", \"pageno\" : \"%@\", \"pagesize\" : \"%@\"}", [RSA encryptString:[DLayout identifier] publicKey:PublicKey], [RSA encryptString:@"UTDID" publicKey:PublicKey], [RSA encryptString:classID publicKey:PublicKey], [RSA encryptString:@"MD5" publicKey:PublicKey], [RSA encryptString:[NSString stringWithFormat:@"%ld",(long)page] publicKey:PublicKey], [RSA encryptString:[NSString stringWithFormat:@"%@", @"10"] publicKey:PublicKey]];

    [PPNetworkHelper POST:url parameters:@{@"json" : par} success:^(id responseObject) {
        
        NSLog(@"数量%lu\n淘宝商品列表:%@\n", [responseObject[@"data"] count], responseObject);
        
        if ([responseObject[@"code"] integerValue] == 1) {
            
            NSArray *dictArr = responseObject[@"data"];
            
            NSMutableDictionary *d = [NSMutableDictionary dictionaryWithDictionary:responseObject];
            
            if (dictArr.count > 0) {
                
                // 转模型数组
                NSArray *modelArr = [TbGoodsListModel mj_objectArrayWithKeyValuesArray:dictArr];
 
                [d removeObjectForKey:@"data"];
                [d setObject:modelArr forKey:@"data"];
            }
            
            if (succcess) {
                
                succcess(d);
                
            }
            
        }else {
            
            [[KYAlertView sharedInstance] showAlertViewWithMessage:responseObject[@"msg"]];
        }
        
    } failure:^(NSError *error) {
        
        if (fail) {
            
            fail(error);
        }
    }];
    
}

@end
